/**
 * Created by fq on 2018/1/15 0015.
 */
'use strict';
angular.module('indexApp')
    .controller('homeCtrl', function ($scope, $state, $rootScope, $timeout, $http) {
        var vm = this;
        $scope.state = $state;
        vm.http = $rootScope.http;
        var swiper = new Swiper('.carousel', {
            pagination: '.swiper-pagination',
            loop:true,
            paginationClickable: true,
            autoplay: 3000,//可选选项，自动滑动
            observer: true,//修改swiper自己或子元素时，自动初始化swiper
            observeParents: true,//修改swiper的父元素时，自动初始化swiper
            effect : 'cube',
            cube: {
                slideShadows: true,
                shadow: true,
                // shadowOffset: 100,
                // shadowScale: 0.6
            }
        });
        vm.banners = [];
        vm.couponList=[1,2,3];
        //
        //
        // var swiper1 = new Swiper('.swiper-container', {
        //     slidesPerView: 'auto',
        //     // spaceBetween: 30,
        //     pagination: {
        //         el: '.swiper-pagination',
        //         clickable: true
        //     }
        // });

        // 获取首页内容
        $http({
            method: 'post',
            url: $rootScope.http + 'index',
            data: {
                // id: id
            }
        })
            .then(function successCallback(res) {
                console.log(res.data);
                if(res.data.code==0){
                    vm.data=res.data.data;
                    vm.banners=vm.data.imgs;
                    $('#rule').html(vm.data.desc)
                }
            }, function errorCallback(res) {// 请求失败执行代码
                $rootScope.alertError()
            });
        //输入关键字搜索
        vm.search = function (key) {
            $state.go('detail.sort', {key: key}, {reload: true})
        };
        vm.go_invite_register=function () {
            window.location.href = $rootScope.http_main + '/#/detail/invite_register';
        }

    });